const API = require('/datas/common.js');

App({
    globalData: {
        userInfo: null,
        nearbyCallback: null,
        messageCallback: null,
        commentCallback: null,
        data: []
    },
    onLaunch: function () {
        console.log('页面加载')
    },
    onShow: function () {
        console.log('页面显示')
    },
    onHide: function () {
        console.log('页面隐藏')

    },
    addNearbyListener: function (nearbyCallback) {
        this.nearbyCallback = nearbyCallback;
    },
    setNearbyData: function (data) {
        if (this.nearbyCallback != null) {
            this.nearbyCallback(data);
        }
        if (this.messageCallback != null) {
            this.messageCallback(data);
        }
    },
    addMessageListener: function (messageCallback) {
        this.messageCallback = messageCallback;
    },
    addCommentListener: function (commentCallback) {
        this.commentCallback = commentCallback;
    },
    setCommentData: function (data) {
        if (this.commentCallback != null) {
            this.commentCallback(data);
        }
        API.setStorage('wuxuegai_comment_' + data.contentId, data);
    },
})
